package leetcode.每日一题;

import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author ：zsy
 * @date ：Created 2022/12/15 7:46 PM
 * @description：
 */
public class 无重叠区间 {
    @Test
    public void test() {

    }

    class Solution {
        public int eraseOverlapIntervals(int[][] intervals) {
            int n = intervals.length;
            if (n == 0) return 0;
            Arrays.sort(intervals, Comparator.comparingInt(o -> o[1]));
            int ans = 1;
            int right = intervals[0][1];
            for (int i = 1; i < n; i++) {
                if (intervals[i][0] >= right) {
                    ans++;
                    right = intervals[i][1];
                }
            }
            return n - ans;
        }
    }
}
